alteryx

LOCATION OPTIMIZER MACROS

Alteryx Location Optimizer Macros can be used to optimize the selection of spatial objects based on criteria set by the user.

Philip // 2022 July

Location Optimizer Macros (LOMs)

There are four types of macros. Though most people can't even remember the name of the elusive fourth type. We have,

  1. Standard Macros - to package up several tools into a single tool
  2. Batch Macros - to run in a loop for every batch of records in the data
  3. Iterative Macros - to run in a loop repeatedly until a condition is met
  4. Location Optimizer Macros

The textbook definition of the Location Optimizer Macro is:

A macro that runs over multiple iterations to determine the best suggested locations to add or remove from a network based on a score.

Where the following definitions apply,

Network
The network is the spatial data that you are optimizing.
Multiple Iterations
Like batch and iterative macros, the LOMs run multiple times to find the best solution.
Suggested Locations
Additional spatial data points to be selected.
Score
Some final measure - to be minimized or maximized - that's used to determine the best location(s).

Why are they useful?

As Location Optimizer Macros are so underutilized, you might well ask what they are for. They are good at finding optimum locations. This could be opening new stores to be closer to your customers, building cell towers that have the greatest coverage, identifying police patrols that are most efficient, or even dividing a region into contiguous areas to apportion workload among sales managers. Any time you're picking locations, there's a potential use case for LOMs.

If you're trying to find store locations near customers, you might ask why not calculate the distance between stores and customers for every combination of stores. The answer is that this is a computationally expensive task and may take a very long time to run.

The Location Optimizer Macro uses two phases,

This means Alteryx LOMs can process larger amounts of data when it comes to deciding locations that might otherwise be unpracticable.

Info

The LOM is very similar to the Optimization Tool. In the Optimization Tool you also want to maximize or minimize a score - the result of the objective function - to find the value of decision variables. LOMs, except you are adding points rather than deducing the value of decision variables.

The Anatomy of a Location Optimizer Macro

Inside the guts of the macro, you will find the following:

Location Optimizer Macro A basic example of a Location Optimizer Macro

An LOM requires at least,

  1. A Macro Input Tool for new potential locations
  2. A Macro Output Tool for the score.
  3. An additional Macro Output Tool (optional) is desirable to output the best locations.

Don't forget to set the macro type to Location Optimizer Macro in the workflow configuration properties tab.

workflow properties tab The Workflow - Configuration tab

interface designer The Interface Designer - Properties tab

Once that's done you can set which Macro Input Tool will give you the Potential Locations Input and which Macro Output Tool will give you the Score Output in the Interface Designer window.

Using the Location Optimizer Macro

It's surprisingly easy to use the LOM. You just need to feed in a list of potential locations and the algorithm will find the best locations according to the score that you calculated within the logic of the macro.

Location optimizer macro usage Using the Location Optimizer Macro in a Standard workflow

The macro configuration options allow you to set how many locations you want to add, the tradeoff between speed and accuracy, and whether you want to want the algorithm to run deterministically (to give you the same result each time) or randomly.

Notice that the required Macro Output Tool (score) gives us a number that is used to find the best location. However, we care very little about the number specifically. It's the second, optional Macro Output Tool (connected directly to the Macro Input Tool) that provides the best location(s) that gives us the answer we're interested in.

Example: Joe's Bike Shops

Now let's explore LOMs for a specific use case. Joe owns six bike shops. He gets investment to double this. The question we want to answer is:

Where should Joe open his new stores?

First let's define the required data.

What is the network?: These are your existing store locations. (This is a fancy term for your current spatial data)
Suggested locations?: The locations of potential new store locations. (You need to provide some viable options)
Score?: In this case, we will go with the total distance between each of your customers and their nearest store.

We also want to specify,

Do we want to maximize or minimize?: Minimize (we want to be closer to our customers).
How many stores we wish to add?: 6

The following illustrates Joe's current bike shop locations,

bike shop locations Joe's existing bike shops. → Potential new bike shops. → The demand / customers.

Step 1: Create the Location Optimizer Macro

The macro for Joe's bike shops is similar to the basic example pictured above.

joe's bike shops macro Joe's bike shops macro.

In this example the score is the weighted average of the distance between each customer and their nearest store. And the nearest score may be either a new store or an existing store. This will help get locations near customers that don't already live near an existing store.

Each customer is not equal. They have a weighting that makes some customers more important than others. This is why we don't simply sum the distances, but take the weighted average.

Once we make this a location optimzer macro from the Workflow - Configuration tab and we can set the properties for Potential Locations Input, Score Output, and Optimize For a Lower Score in the Interface Designer.

Step 2: Create the workflow

Now it's ready to be used in a workflow. This is trivial. We connect up the data to the macro, set the number of new locations to add to 6 in the macro configuration, and run the macro.

joe's bike shops workflow Joe's bike shops workflow.

The output is the Score - a number that is used to find the best location but ultimately not useful to us - and the six selected locations.

Step 3: Results

It really is as simple as that. The macro finds the best locations in accordance with the way we calculate the score. It takes care of running for multiple iterations and spits out the best locations. the results are mapped below,

joe's bike shops workflow Joe's suggested new bike shop locations.

Warning

I have been a bit liberal with the term 'best' when referring to the 'best locations'. As the algorithm starts with a random guess that it improves upon over multiple iterations, the result may not be optimum in the true sense of the word. Two separate runs may yield different results. But you may ensure better results by increasing the number of iterations in the LOM configuration.

Conclusion

I started to learn about Location Optimizer Macros when I was working on a project for a client to equally distribute the zip codes the US customers live in into distinct contiguous regions with equal weighting. Not a common use case, but it goes to show how versatile the macro can be with some proper understanding of how it works. I hope this blog at least shows you what the LOM can do and sheds a little bit of light on the oft' forgotten fourth type of macro. Now go fourth and optimize.